﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using VIBlend.WPF.Controls;

namespace AnonsaiWPF.CSharp.DataGridViewDemos
{
    
    [Category("VIBlend.WPF.Examples")]
    public partial class SelectionDemo : Window, IWindow
    {
        #region IWindow Members

        public void DetachContent()
        {
            RemoveLogicalChild(Content);
        }

        public Grid Root
        {
            get
            {
                return this.LayoutRoot;
            }
        }
        #endregion
        public void SetTheme()
        {
            dataGrid.FontFamily = new FontFamily("Tahoma");
        }
  
        public SelectionDemo()
        {
            InitializeComponent();

            PrepareGridData();

            dataGrid.ItemsSource = listSaleRecord;            
            dataGrid.RowsHierarchy.Visible = false;       
         }

        #region Sample Data

      
        public List<EmployeeSaleRecordValidationDemo> listSaleRecord = new List<EmployeeSaleRecordValidationDemo>();

        private void PrepareGridData()
        {
            const int rowsToLoad = 1000;
            listSaleRecord.Clear();

            Random rand = new Random();

            for (int i = 0; i < rowsToLoad; i++)
            {
                int productId = rand.Next(0, productNames.Length / 2 - 1);
                int quantity = rand.Next(1, 5);
                listSaleRecord.Add(new EmployeeSaleRecordValidationDemo(
                    productId,
                    quantity)
                    );
            }
        }

        static string[,] productNames = new string[,] 
                {
                    {"Black Tea", "2"},
                    {"Green Tea", "1"},
                    {"Caffè Espresso", "1"},
                    {"Doubleshot Espresso", "3"},
                    {"Caffè Latte", "2"},
                    {"White Chocolate Mocha", "2"},
                    {"Caramel Latte", "3"},
                    {"Caffè Americano", "2"},
                    {"Cappuccino", "2"},
                    {"Espresso Truffle", "3"},
                    {"Espresso con Panna", "2"},
                    {"Peppermint Mocha Twist", "2"}
                };

        #endregion

        // Sets the selection mode to cells selection.
        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            if (this.dataGrid == null)
                return;

            this.dataGrid.SelectionMode = VIBlend.WPF.Controls.DataGrid.SELECTION_MODE.CELL_SELECT;
        }

        // Sets the selection mode to full column selection.
        private void RadioButton_Checked_1(object sender, RoutedEventArgs e)
        {
            if (this.dataGrid == null)
                return;

            this.dataGrid.SelectionMode = VIBlend.WPF.Controls.DataGrid.SELECTION_MODE.FULL_COLUMN_SELECT;
        }

        // Sets the selection mode to full row selection.
        private void RadioButton_Checked_2(object sender, RoutedEventArgs e)
        {
            if (this.dataGrid == null)
                return;
            
            this.dataGrid.SelectionMode = VIBlend.WPF.Controls.DataGrid.SELECTION_MODE.FULL_ROW_SELECT;
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            this.listSaleRecord.Clear();
            this.listSaleRecord = null;
            base.OnClosing(e);
            this.dataGrid.Dispose();
            this.dataGrid = null;
        }
    } // class CellEditing
}
